//
//  UserInfo.m
//  太平卓客
//
//  Created by rimi on 15/7/10.
//  Copyright (c) 2015年 rimi. All rights reserved.
//

#import "UserInfo.h"
#define USER_NAME @"urm"
#define LOGIN_STATUS @"loginStatus"
#define TOKEN @"token"
#define USER_ID @"userId"
#define DEVICE_ID @"deviceId"
#define PASSWORD @"password"
#define USER_KEY @"key"
#define HEADIMAGE @"headImage"
#define PASSPORT @"passport"
#define BALANCE @"balance"
#define PHONENUMBER @"phoneNumber"
#define STOREIMAGE @"storeImage"
#define LOGO @"logo"
#define UID @"uid"
static UserInfo *userInfo = nil;
@implementation UserInfo

+ (instancetype)sharedUserInfo
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        userInfo = [[UserInfo alloc] init];
    });
    return userInfo;
}

//从沙盒里面读取数据
- (void)loadUserInfoFromSandbox{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    self.username = [userDefaults objectForKey:USER_NAME];
    self.userId   = [userDefaults objectForKey:USER_ID];
    self.token    = [userDefaults objectForKey:TOKEN];
    self.deviceId = [userDefaults objectForKey:DEVICE_ID];
    self.phoneNumber = [userDefaults objectForKey:PHONENUMBER];
    self.loginStatus = [userDefaults boolForKey:LOGIN_STATUS];
    self.key = [userDefaults objectForKey:USER_KEY];
    self.headImage = [userDefaults objectForKey:HEADIMAGE];
    self.passport = [userDefaults objectForKey:PASSPORT];
    self.balance = [userDefaults objectForKey:BALANCE];
    self.storeImage = [userDefaults objectForKey:STOREIMAGE];
    self.logo = [userDefaults boolForKey:LOGO];
    self.uid = [userDefaults objectIsForcedForKey:UID];
}
//把数据存入沙盒
- (void)saveUserInfoToSandbox{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:self.username forKey:USER_NAME];
    [userDefaults setObject:self.userId forKey:USER_ID];
    [userDefaults setObject:self.token forKey:TOKEN];
    [userDefaults setObject:self.deviceId forKey:DEVICE_ID];
    [userDefaults setObject:self.phoneNumber forKey:PHONENUMBER];
    [userDefaults setObject:self.key forKey:USER_KEY];
    [userDefaults setBool:self.loginStatus forKey:LOGIN_STATUS];
    [userDefaults setObject:self.headImage forKey:HEADIMAGE];
    [userDefaults setObject:self.passport forKey:PASSPORT];
    [userDefaults setObject:self.balance forKey:BALANCE];
    [userDefaults setObject:self.storeImage forKey:STOREIMAGE];
    [userDefaults setBool:self.logo forKey:LOGO];
    [userDefaults setInteger:self.uid forKey:UID];
    [userDefaults synchronize];
}
@end
